package com.example.myapplication.tack_21;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.example.myapplication.R;
import com.example.myapplication.tack_21.data.WodeData;
import com.example.myapplication.utils.Common;
import com.example.myapplication.utils.OkHttpTool;
import com.example.myapplication.utils.StateData;
import com.google.gson.Gson;

import org.json.JSONException;
import org.json.JSONObject;

public class CaseActivity extends AppCompatActivity {
    private ImageView exit;
    private ImageView img;
    private TextView name;
    private TextView jobName;
    private TextView practiceNo;
    private TextView qtw;
    private Gson gson;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tack_21_activity_case);
        init();
        Intent intent = getIntent();
        String stringExtra = intent.getStringExtra(Common.COMMON);
        WodeData.RowsDTO rowsDTO = gson.fromJson(stringExtra, WodeData.RowsDTO.class);
        exit_();
        getAnLie(rowsDTO);
        qtw_(rowsDTO);
    }

    private void qtw_(WodeData.RowsDTO rowsDTO) {
        qtw.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(CaseActivity.this, AnLieXQActivity.class);
                Gson gson = new Gson();
                String json = gson.toJson(rowsDTO);
                intent.putExtra(Common.COMMON,json);
                CaseActivity.this.startActivity(intent);
            }
        });
    }


    private void getAnLie(WodeData.RowsDTO rowsDTO) {

        if(!TextUtils.isEmpty(rowsDTO.getName())){
            name.setText(rowsDTO.getName());
        }else{
            name.setText("暂无信息");
        }
        if(!TextUtils.isEmpty(rowsDTO.getImageUrls())){
            Glide.with(CaseActivity.this).load(OkHttpTool.URL + rowsDTO.getImageUrls()).into(img);
        }
        if(!TextUtils.isEmpty( rowsDTO.getJobName())){
            jobName.setText(rowsDTO.getJobName());
        }else{
            jobName.setText("暂无信息");
        }
        if(!TextUtils.isEmpty(rowsDTO.getQuestion())){
            practiceNo.setText(rowsDTO.getQuestion());
        }else{
            practiceNo.setText("暂无信息");
        }


    }

    private void exit_() {
        exit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CaseActivity.this.finish();
            }
        });
    }

    private void init() {
        exit = findViewById(R.id.exit);
        img = findViewById(R.id.img);
        name = findViewById(R.id.name);
        jobName = findViewById(R.id.jobName);
        practiceNo = findViewById(R.id.practiceNo);
        qtw = findViewById(R.id.qtw);
        gson = new Gson();
    }
}